<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">

    <script src="/lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
    <script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <script src="/lib/jq-module/jquery.particleground.min.js" charset="utf-8"></script>
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>

<body>
    <div class="layui-form layuimini-form">
        <div class="layui-form-item">
            <label class="layui-form-label required">姓名</label>
            <div class="layui-input-block">
                <input type="text" name="p_name" lay-verify="required" lay-reqtext="姓名不能为空" placeholder="请输入用户名"
                    value="" class="layui-input">
                <!-- <tip>填写自己管理账号的名称。</tip> -->
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">性别</label>
            <div class="layui-input-block">
                <input type="radio" name="p_sex" value="男" title="男" checked="">
                <input type="radio" name="p_sex" value="女" title="女">
            </div>
        </div>

        <!-- <div class="layui-form-item">
            <label class="layui-form-label">生日</label>
            <div class="layui-input-block">
                <input type="text" name="birthday" id="date" lay-verify="date" placeholder="yyyy-MM-dd"
                    autocomplete="off" class="layui-input">
            </div>
        </div> -->

        <div class="layui-form-item">
            <label class="layui-form-label required">购房时间</label>
            <div class="layui-input-block">
                <input type="date" name="p_purchaseHouseTime" lay-verify="required" lay-reqtext="手机不能为空" placeholder="请输入手机"
                    value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">付款方式</label>
            <div class="layui-input-block">
                <input type="radio" name="p_paymentMethod" value="全款" title="全款" checked="">
                <input type="radio" name="p_paymentMethod" value="分期" title="分期">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">购房价格</label>
            <div class="layui-input-block">
                <input type="text" name="p_housePice" placeholder="请输入金额单位为W" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">房号</label>
            <div class="layui-input-block">
                <input type="text" name="p_houseLocation" placeholder="请输入房号" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">紧急联系人</label>
            <div class="layui-input-block">
                <input type="text" name="p_emergencyContact" placeholder="请输入紧急联系人手机号码或电话号码" value="" class="layui-input">
            </div>
        </div>



        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
            </div>
        </div>
    </div>
    <script>
        layui.use(['form', 'upload', 'element'], function () {
            var form = layui.form,
                layer = layui.layer,
                upload = layui.upload,
                element = layui.element,
                laydate = layui.laydate,
                $ = layui.$;

            // 渲染日期组件
            laydate.render({
                elem: '#date'
            });
            //监听提交
            form.on('submit(saveBtn)', function (data) {
                var index = layer.alert(JSON.stringify(data.field), {

                    title: '最终的提交信息'
                }, function () {
                    console.log(data.field)

                  
                


                    // 关闭弹出层
                    layer.close(index);

                    var iframeIndex = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(iframeIndex);

                });
                $.ajax({
                    url: "http://localhost:8080/purchasehouse/purchasehouseAdd",
                    contentType:"application/json",
                    data: JSON.stringify(data.field),
                    type: "post",
                    success: function (result) {
                        console.log(data.field)
                        if (result.code == 0) {

                            var iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.msg("添加成功");
                            parent.layer.close(iframeIndex);
                        } else {
                            var iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.msg("添加失败");
                            parent.layer.close(iframeIndex);
                        }
                    },
                    dataType: "json"
                })


                return false;
            });

        });
    </script>
</body>

</html>